$(document).ready(function() {
	$.ajax({
         url: basePath+"diseaseHistory/tofindHis.spring",
         type: "POST",
         dataType: 'json',
         cache: false,
         success: function (ret) {
         console.log(ret);
             if(ret!=null){
             	if(ret.list!=null&&ret.list.length>0){
             		var data=ret.list[0];
             		$("#historyName").text(data.historyName);
             		//既往史开始
             		$("#bodyHealth").val(data.bodyHealth);
//             		$("#bodyWeak").val(data.bodyWeak);
             		
             		$("#wasSickSel").val(data.wasSick.substring(0,1));
             		if(data.wasSick.substring(0,1)=='0'){
             			$("#wasSick").hide();
             		}else{
             			$("#wasSick").show();
             			$("#wasSick").val(data.wasSick.substring(1,data.wasSick.length));
             		}
             		$("#operationSel").val(data.majorTrauma.substring(0,1));
             		if(data.majorTrauma.substring(0,1)=='0'){
             			$("#majorTrauma").hide();
             		}else{
             			$("#majorTrauma").show();
             			$("#majorTrauma").val(data.majorTrauma.substring(1,data.majorTrauma.length));	
             		}
             		
             		//手術
             		$("#operationSel").val(data.operation.substring(0,1));
             		if(data.operation.substring(0,1)=='0'){
             			$("#operation").hide();
             		}else{
             			$("#operation").show();
             			$("#operation").val(data.operation.substring(1,data.operation.length));	
             		}
             		//过敏
             		$("#allergySel").val(data.allergy.substring(0,1));
             		if(data.allergy.substring(0,1)=='0'){
             			$("#allergy").hide();
             		}else{
             			$("#allergy").show();
             			$("#allergy").val(data.allergy.substring(1,data.allergy.length));	
             		}
             		$("#timelyVaccination").val(data.timelyVaccination);
             		$("#transfusion").val(data.transfusion);
             		//婚育史开始
             		$("#marriage").val(data.marriage);
             		$("#menophania").val(data.menophania);
             		$("#continueTime").val(data.continueTime);
             		$("#intervalTime").val(data.intervalTime);
             		$("#pausimenia").val(data.pausimenia);
             		$("#endMeniaTime").val(data.endMeniaTime);
             		$("#pregnancies").val(data.pregnancies);
             		$("#aborticide").val(data.aborticide);
             		$("#production").val(data.production);
//             		家族史
             		$("#cancerSel").val(data.cancer.substring(0,1));
             		if(data.cancer.substring(0,1)=='0'){
             			$("#cancer").hide();
             		}else{
             			$("#cancer").show();
             			$("#cancer").val(data.cancer.substring(1,data.cancer.length));	
             		}
             		$("#psychogenySel").val(data.psychogeny.substring(0,1));
             		if(data.psychogeny.substring(0,1)=='0'){
             			$("#psychogeny").hide();
             		}else{
             			$("#psychogeny").show();
             			$("#psychogeny").val(data.psychogeny.substring(1,data.psychogeny.length));	
             		}
             		$("#highBloodPressure").val(data.highBloodPressure);
             		$("#diabetes").val(data.diabetes);
             		$("#stroke").val(data.stroke);
             		$("#coronaryHeart").val(data.coronaryHeart);
             		$("#geneticDiseaseSel").val(data.geneticDisease.substring(0,1));
             		if(data.geneticDisease.substring(0,1)=='0'){
             			$("#geneticDisease").hide();
             		}else{
             			$("#geneticDisease").show();
             			$("#geneticDisease").val(data.geneticDisease.substring(1,data.geneticDisease.length));	
             		}
             		$("#disabilitySel").val(data.disability.substring(0,1));
             		if(data.disability.substring(0,1)=='0'){
             			$("#disability").hide();
             		}else{
             			$("#disability").show();
             			$("#disability").val(data.disability.substring(1,data.disability.length));	
             		}
             		//个人史
             		$("#birthPlace").val(data.birthPlace);
             		$("#educationDegree").val(data.educationDegree);
             		$("#birthPlace").val(data.birthPlace);
             		$("#localDiseaseSel").val(data.localDisease.substring(0,1));
             		if(data.localDisease.substring(0,1)=='0'){
             			$("#localDisease").hide();
             		}else{
             			$("#localDisease").show();
             			$("#localDisease").val(data.localDisease.substring(1,data.localDisease.length));	
             		}
             		$("#economics").val(data.economics);
             		$("#profession").val(data.profession);
             		$("#sexualBehavior").val(data.sexualBehavior);
             		$("#presentIness").val(data.presentIness);
             		$("#did").val(data.id);
             		
             	}else{
               	 $("#did").val(0);
                }
             }else{
            	 $("#did").val(0);
             }
         }
     });
	});


	function localSel() {
		var localDiseaseSel = $("#localDiseaseSel").val();
		if(localDiseaseSel==1){
		$("#localDisease").show();
		}else{
			$("#localDisease").hide();
		}
	}
	
	//既往史进入婚育史
	function tomenHis(){
	$("#previousHistory").hide();
	$("#menstruationHistory").show();
	}
	//婚育史进入既往史
	function topreviousHis(){
	$("#previousHistory").show();
	$("#menstruationHistory").hide();
	}
	//婚育史进入家族史
	function tofamilyHis(){
	$("#menstruationHistory").hide();
	$("#familyHistory").show();
	}
	//返回婚育史
	function backMenHis(){
	$("#menstruationHistory").show();
	$("#familyHistory").hide();
	}
	//家族史进入个人史
	function toPerson(){
	$("#familyHistory").hide();
	$("#persionHistory").show();
	}
	//个人史进入家族史
	function backtoperson(){
	$("#familyHistory").show();
	$("#persionHistory").hide();
	} 
	
	function toSave(){
		var id=$("#did").val();
		var $loadingToast = $('#loadingToast1');
		if ($loadingToast.css('display') != 'none') {
			return;
		}
		$loadingToast.show();
		//既往史获取数据
		var bodyHealth=$("#bodyHealth").val();
		var bodyWeak=$("#bodyWeak").val();
		var wasSickSel=$("#wasSickSel").val();
		var wasSick=$("#wasSick").val();
		if(wasSickSel==1){
			wasSick=wasSickSel+wasSick;
		}else{
			wasSick=wasSickSel;
		}
		var bodyHealth=$("#bodyHealth").val();
		var majorTraumaSel=$("#majorTraumaSel").val();//重大外伤史
		var majorTrauma=$("#majorTrauma").val();
		if(majorTraumaSel==1){
			majorTrauma=majorTraumaSel+majorTrauma;
		}else{
			majorTrauma=majorTraumaSel;
		}
		var operationSel=$("#operationSel").val();
		var operation=$("#operation").val();
		if(operationSel==1){
			operation=operationSel+operation;
		}else{
			operation=operationSel;
		}
		var allergySel=$("#allergySel").val();
		var allergy=$("#allergy").val();
		if(allergySel==1){
			allergy=allergySel+allergy;
		}else{
			allergy=allergySel;
		}
		var timelyVaccination=$("#timelyVaccination").val();
		var transfusion=$("#transfusion").val();
		//婚育史
		var marriage=$("#marriage").val();
		var menophania=$("#menophania").val();
		
		var continueTime=$("#continueTime").val();
		
		var intervalTime=$("#intervalTime").val();
		
		var pausimenia=$("#pausimenia").val();
		var endMeniaTime=$("#endMeniaTime").val();
		
		var pregnancies=$("#pregnancies").val();
		
		var production=$("#production").val();
		
		var aborticide=$("#aborticide").val();
		//家族史
		var cancerSel=$("#cancerSel").val();
		var cancer=$("#cancer").val();
		if(cancerSel==1){
			cancer=cancerSel+cancer;
		}else{
			cancer=cancerSel;
		}
		var psychogenySel=$("#psychogenySel").val();
		var psychogeny=$("#psychogeny").val();
		if(psychogenySel==1){
			psychogeny=psychogenySel+psychogeny;
		}else{
			psychogeny=psychogenySel;
		}
		var highBloodPressure=$("#highBloodPressure").val();
		var diabetes=$("#diabetes").val();
		var stroke=$("#stroke").val();
		var coronaryHeart=$("#coronaryHeart").val();
		var geneticDiseaseSel=$("#geneticDiseaseSel").val();
		var geneticDisease=$("#geneticDisease").val();
		if(geneticDiseaseSel==1){
			geneticDisease=geneticDiseaseSel+geneticDisease;
		}else{
			geneticDisease=geneticDiseaseSel+"";
		}
		var disabilitySel=$("#disabilitySel").val();
		var disability=$("#disability").val();
		if(disabilitySel==1){
			disability=disabilitySel+disability;
		}else{
			disability=disabilitySel;
		}
		//个人史
		var birthPlace=$("#birthPlace").val();
		var presentIness=$("#presentIness").val();
		var educationDegree=$("#educationDegree").val();
		var localDiseaseSel=$("#localDiseaseSel").val();
		var localDisease=$("#localDisease").val();
		if(localDiseaseSel==1){
			localDisease=localDiseaseSel+localDisease;
		}else{
			localDisease=localDiseaseSel;
		}
		var economics=$("#economics").val();
		var profession=$("#profession").val();
		
		var sexualBehavior=$("#sexualBehavior").val();
	
		$.ajax({
	         url: basePath+"diseaseHistory/toSave.spring",
	         data: {
	        	 bodyHealth:bodyHealth,
	        	 bodyWeak:bodyWeak,
	        	 wasSick:wasSick,
	        	 majorTrauma:majorTrauma,
	        	 operation:operation,
	        	 allergy:allergy,
	        	 timelyVaccination:timelyVaccination,
	        	 transfusion:transfusion,
	        	 marriage:marriage,
	        	 menophania:menophania,
	        	 continueTime:continueTime,
	        	 intervalTime:intervalTime,
	        	 pausimenia:pausimenia,
	        	 endMeniaTime:endMeniaTime,
	        	 pregnancies:pregnancies,
	        	 production:production,
	        	 aborticide:aborticide,
	        	 cancer:cancer,
	        	 psychogeny:psychogeny,
	        	 highBloodPressure:highBloodPressure,
	        	 diabetes:diabetes,
	        	 stroke:stroke,
	        	 coronaryHeart:coronaryHeart,
	        	 geneticDisease:geneticDisease,
	        	 disability:disability,
	        	 birthPlace:birthPlace,
	        	 educationDegree:educationDegree,
	        	 localDisease:localDisease,
	        	 economics:economics,
	        	 profession:profession,
	        	 sexualBehavior:sexualBehavior,
	        	 presentIness:presentIness,
	        	 id:id
	         },
	         type: "POST",
	         dataType: 'json',
	         cache: false,
	         success: function (ret) {
	             if(ret.content=="success"){
	            	 setTimeout(function() {
			   				$loadingToast.hide();
			   				$("#toast1").show();
			   				setTimeout(function() {
			   				    var w_height = $(window).height();
			   				    $('.theleftmenu').css('height',w_height);
			   				    $('.theleftmenu').css('display','block');
				   				 $(".historymenu").hide();
				   				 setTimeout(function(){
				   				$('.historymenu,.bg_mark').css('display','none');
				   				$('.historymenu .leftmenu_con ').css('display','none');
			   									},200); 
			   				    $('.theleftmenu .bg_mark').css('display','block');
			   				    $('.theleftmenu .theleftmenu_con ' ).stop().animate({ left: '0' }, 400);
					            $("#toast1").hide();
							}, 800);}, 800);
	             }else{
	            	 alert("保存失败"); 
	             }
	         }
	     });	
	}
	
